package com.titaniume.java1;

import org.junit.Test;

import java.util.Comparator;

/**
 *@program: JavaSenior
 *@description:
 *@author: renfei.huang
 *@create: 2021-11-02 11:16
 */
public class LambdaTest {

    @Test
    public  void test1(){

        Runnable runnable1 = new Runnable() {
            @Override
            public void run() {
                System.out.println("java是世界上最好的语言");
            }
        };
        runnable1.run();

        System.out.println("*****************************");

        Runnable runnable2 = () -> System.out.println("java是世界上最好的语言");
        runnable2.run();

    }


    @Test
    public void test2(){


        //传统方式
        Comparator<Integer> com1 = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1, o2);
            }
        };
        int compare1 = com1.compare(10, 12);
        System.out.println(compare1);


        System.out.println("*****************************");


        //Lambda表达式
        Comparator<Integer> com2 = (o1,o2) -> Integer.compare(o1,o2);
        int compare2 = com2.compare(10, 12);
        System.out.println(compare2);

        System.out.println("*****************************");

        //方法引用
        Comparator<Integer> com3 = Integer :: compare;
        int compare3 = com3.compare(10, 12);
        System.out.println(compare3);


    }

}
